﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Stoplight.Base;
using Stoplight.Events;
using System.Windows.Threading;

namespace Stoplight.Views.StatusBar
{
    public class StatusBarPresenter : PresenterBase<IStatusBarView>
    {
        private DispatcherTimer timer = new DispatcherTimer();

        string LeftStatusBarMessage
        {
            get { return FindName<TextBlock>("sbrLeft").Text; }
            set { FindName<TextBlock>("sbrLeft").Text = value; }
        }
        string RightStatusBarMessage
        {
            get { return FindName<TextBlock>("sbrRight").Text; }
            set { FindName<TextBlock>("sbrRight").Text = value; }
        }

        protected override void OnViewSet()
        {
            EventAggregator.GetEvent<LightChangedEvent>().Subscribe(LightChangedHandler);

            timer.Interval = new TimeSpan(1000);
            timer.Tick += new EventHandler(timer_Tick);
            timer.Start();
        }

        void timer_Tick(object sender, EventArgs e)
        {
            RightStatusBarMessage = string.Format("{0}", DateTime.Now);
        }


        public void LightChangedHandler(LightChangedEvent e)
        {
            LeftStatusBarMessage = string.Format("Color changed to {0}", e.CurrentColor);
        }
    }
}
